package com.youxue.teachin.set.main.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.Navigator;
import com.library.xtype.DefaultNuwaItemBinder;
import com.youxue.teachin.R;
import com.youxue.teachin.set.main.vo.KeyValueVO;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-06 10:20
 * @version: 9.1.0
 */
public class KeyValueBinder extends DefaultNuwaItemBinder<KeyValueVO> implements OnClickListener {
    private View mRootView;
    private TextView mKey;
    private TextView mValue;
    private ImageView mRightArrows;
    KeyValueVO mKeyValueVO = null;

    @Override
    public View onCreateView(View convertView, ViewGroup parent, LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.set_main_key_value_binder, parent, false);
        initView(view);
        return view;
    }

    @Override
    public void onBindView(int positionOfFeeds, View convertView, ViewGroup parent, KeyValueVO vo) {
        mKeyValueVO = vo;
        mKey.setText(vo.mKey);
        mValue.setText(vo.mValue);
        mRootView.setTag(vo);
    }

    private void initView(View rootView) {
        mRootView = rootView;
        mKey = (TextView)rootView.findViewById(R.id.key);
        mValue = (TextView)rootView.findViewById(R.id.value);
        mRightArrows = (ImageView)rootView.findViewById(R.id.right_arrows);

        mRootView.setOnClickListener(this);
    }

    OnClickListener mOnClickListener;
    @Override
    public void setOnClickListener(OnClickListener listener) {
        super.setOnClickListener(listener);
        mOnClickListener = listener;
    }

    @Override
    public void onClick(View v) {
        int type = mKeyValueVO.type;
        if (type == KeyValueVO.TYPE_NIKE_NAME) {
            new Navigator.Builder()
                .setPageName("set_chagne_text")
                .addParameter("type", type)
                .addParameter("text", mKeyValueVO.mValue == null ? "" : mKeyValueVO.mValue)
                .build().open();
        } else if (type == KeyValueVO.TYPE_JIESHAO) {
            new Navigator.Builder()
                .setPageName("set_chagne_text")
                .addParameter("type", type)
                .addParameter("text", mKeyValueVO.mValue == null ? "" : mKeyValueVO.mValue)
                .build().open();
        } else if (type == KeyValueVO.TYPE_PHONE) {
            new Navigator.Builder()
                .setPageName("set_self_account")
                .addParameter("type", type)
                .addParameter("text", mKeyValueVO.mValue == null ? "" : mKeyValueVO.mValue)
                .build().open();
        } else if (type == KeyValueVO.TYPE_XUEDUAN) {
            new Navigator.Builder().setPageName("set_xuekexueduan")
                .build().open();
        } else if (type == KeyValueVO.TYPE_ARREA) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(v);
            }
        }
    }
}
